package Java8Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest1 {

    public static void main(String[] args) {
        List<Dish> menu = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Dish dish = new Dish();
            dish.setName("菜单"+i);
            dish.setCalories(100 * i);
            menu.add(dish);
        }

        List<String> lowCaloricDishesName =
//                menu.stream()
                menu.parallelStream()
                    .filter(d -> d.getCalories() < 400)
                    .sorted(Comparator.comparing(Dish::getCalories))
                    .map(Dish::getName)
                    .collect(Collectors.toList());
        System.out.println(lowCaloricDishesName);

        IntSummaryStatistics menuStatistics =
                menu.stream().collect(Collectors.summarizingInt(Dish::getCalories));
        System.out.println(menuStatistics);

        String shortMenu = menu.stream().map(Dish::getName).collect(Collectors.joining(", "));
        System.out.println(shortMenu);
    }
}
